﻿Namespace EIB.Bus.FT12
    Public NotInheritable Class FT12_FrameFixed
        Inherits FT12_FrameControl

        Sub New(direction As FT12_FrameDirection, toggleFCB As Boolean, FCV As Boolean, messageCode As Byte)
            MyBase.New(FT12_FrameType.Fixed, direction, toggleFCB, FCV, messageCode)

            Dim ft12data As Byte() = New Byte(3) {}
            ft12data(0) = FT12_FrameBase.FT12_STARTFIXED
            ft12data(1) = _Control
            ft12data(2) = _Control
            ft12data(3) = FT12_FrameBase.FT12_END

            _FT12_Data = ft12data
        End Sub

        Sub New(direction As FT12_FrameDirection, dataFlowControl As Boolean, messageCode As Byte)
            MyBase.New(FT12_FrameType.Fixed, direction, dataFlowControl, messageCode)

            Dim ft12data As Byte() = New Byte(3) {}
            ft12data(0) = FT12_FrameBase.FT12_STARTFIXED
            ft12data(1) = _Control
            ft12data(2) = _Control
            ft12data(3) = FT12_FrameBase.FT12_END

            _FT12_Data = ft12data
        End Sub

        Sub New(busData As Byte())
            MyBase.New(busData, 1)

            If busData.Length <> 4 Then Throw New EIB.Exceptions.EIBDataDecodeException("")
            If busData(0) <> FT12_FrameBase.FT12_STARTFIXED Then Throw New EIB.Exceptions.EIBDataDecodeException("")
            If busData(1) <> busData(2) Then Throw New EIB.Exceptions.EIBDataDecodeException("")
            If busData(3) <> FT12_FrameBase.FT12_END Then Throw New EIB.Exceptions.EIBDataDecodeException("")
        End Sub


        Public Overrides Function ToInfoList() As List(Of InfoBase)
            Dim list As New List(Of InfoBase)

            list.Add(New Info("Type", String.Format("{0} (0x{0:X})", Type)))
            list.Add(New Info("Direction", String.Format("{0} (0x{0:X})", Direction)))
            list.Add(New Info("IsPrimary", PrimaryMessage))
            list.Add(New Info("FCB", ToggleFCB))
            list.Add(New Info("FCV", FCV))
            list.Add(New Info("FT1.2 Message Code", String.Format("{0} (0x{0:X})", MessageCode)))

            Return list
        End Function
    End Class
End Namespace